//
//  Order.m
//  Menu
//
//  Created by trimad on 11-11-11.
//  Copyright 2011 Trimad Group. All rights reserved.
//

#import "Order.h"

#import "Item.h"
#import "OrderItem.h"

@implementation Order

@synthesize note;
@synthesize orderItems;

// <item_code, orderItem>
NSMutableDictionary *orderItemDic;

- (void)updateOrderItem:(OrderItem *)orderItem {
	if (orderItemDic == nil) {
		orderItemDic = [[NSMutableDictionary alloc] init];
	}
	OrderItem *existOrderItem = [orderItemDic objectForKey:orderItem.item.code];
	if (existOrderItem == nil && orderItem.quantity > 0) {
		[orderItemDic setObject:orderItem forKey:orderItem.item.code];
		
	} else {
		if (orderItem.quantity > 0) {
			[orderItemDic setObject:orderItem forKey:orderItem.item.code];
		} else {
			[orderItemDic removeObjectForKey:orderItem.item.code];
		}
	}
}

- (OrderItem *)getOrderItem:(NSString *)itemCode {
	return [orderItemDic objectForKey:itemCode];
}

- (OrderItem *)removeOrderItem:(NSString *)itemCode {
	OrderItem *orderItem = [orderItemDic objectForKey:itemCode];
	[orderItemDic removeObjectForKey:itemCode];
	return orderItem;
}
@end
